﻿        <!DOCTYPE html>
        <html lang="en">
        <head>


        <!-- TEAM STATUS -->
        <!--/HEADER -->

        <!-- PAGE -->

        <!-- /SIDEBAR -->

        <!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->

        <!-- /PAGE HEADER -->
        <!-- DATA TABLES -->
        <div class="row">
        <div class="col-md-12">
        <!-- BOX -->
        <div class="box border green">
        <div class="box-title">
        <h4><i class="fa fa-table"></i>新闻列表</h4>
        <div class="tools hidden-xs">
        <a href="#box-config" data-toggle="modal" class="config">
        <i class="fa fa-cog"></i>
        </a>
        <a href="javascript:;" class="reload">
        <i class="fa fa-refresh"></i>
        </a>
        <a href="javascript:;" class="collapse">
        <i class="fa fa-chevron-up"></i>
        </a>
        <a href="javascript:;" class="remove">
        <i class="fa fa-times"></i>
        </a>
        </div>
        </div>
        <div class="box-body">
        <form role="form" >
        <table id="datatable1" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
        <thead>
        <tr>

        <th>ID</th>
        <th>管理员</th>
        <th>pid</th>
        <th>新闻类型</th>



        </tr>
        </thead>
        <tbody>
        <?php foreach($power as $value){?>
        <tr class="gradeX" pid="<?php echo $value['pid']?>" pid="0" level="1">
        <td><?php echo $value['id']?></td>
        <td>
         <button type="button" id="<?php echo $value['id']?>" class="btn btn-purple">+</button>

        <?php echo $value['name']?></td>
        <td><?php echo $value['pid']?></td>

        <td>
        <a href="index.php?c=power&a=edit&admin=1&id=<?php echo $value['id']?>"
        class="btn btn-info"><i class="fa fa-pencil-square-o"></i> 编辑</a>

        <a href="index.php?c=power&a=del&admin=1&id=<?php echo $value['id']?>"  onclick="return confirm('真的要删除吗？')" class="btn btn-2g btn-danger del"><i class="fa fa-trash-o"></i> 删除</a>

        </td>

        </tr>
        <?php } ?>


        </tbody>

        </table>
        <div class="row"><div class="col-sm-12">
        <div class="pull-left">
        <div class="dataTables_info" id="datatable1_info">Showing 1 to 10 of 57 entries</div>
        </div>
        <div class="pull-right">
        <div class="dataTables_paginate paging_bs_full" id="datatable1_paginate">
        <ul class="pagination">



        </ul>
        </div>
        </div>

        <div class="clearfix"></div>
        </div>
        </div>

        </form>


        </div>
        </div>
        <!-- /BOX -->
        </div>
        </div>

		<script src="resources/admin/js/jquery/jquery-2.0.3.min.js""></script>
		<script type="text/javascript">



	 $(function(){
           $("tbody").on('click','.btn',function(){

             var obj=$(this);
    		var tr_obj=$(this).parent().parent();



          var pid = tr_obj.attr('pid');//获取当前行的pid属性值

          var index = $('tr[pid='+pid+']').index(tr_obj);

          var len = $('tr[pid='+pid+']').length-1;


          // $('tr[pid='+0+']').index(tr_obj);//获取当前对象集合里面对应传递的对象的下标值

            var id = $(this).attr('id');
            if('+'==$(this).text()){
                var level = parseInt(tr_obj.attr('level'));
                    left = level*40;
                    level++;
                  $(this).text('-')
                  $.ajax({
                    type:'get',
                    url:'index.php?c=power&a=list&admin=1&id='+id,
                    dataType:'json',
                    success:function(json){
                         var html= '';
                         for(i in json){
                           html+='<tr level="'+level+'" pid="'+id+'" class="gradeX">';
                            html+='<td>'+json[i].id+'</td>';
                            html+='<td style="padding-left:'+left+'px"><button type="button" id="'+json[i].id+'" class="btn btn-purple">+</button>'
                            html+=''+json[i].name+'</td>';
                            html+='<td>'+json[i].pid+'</td>';
                            html+='<td>';
                            html+='<a href="index.php?c=power&a=edit&admin=1&id='+json[i].id+'"';
                           html+='class="btn btn-info"><i class="fa fa-pencil-square-o"></i> 编辑</a>';
                        html+='<a href="index.php?c=power&a=del&admin=1&id='+json[i].id+'"';
                        html+='onclick="" class="btn btn-2g btn-danger del">';
                        html+= '<i class="fa fa-trash-o"></i> 删除</a>';
                        html+= '</td>';
                        html+='</tr>';
                         }
                          	html+='<tr pid="'+json[i].pid+'" style="display:none"></tr>';
                                                   //给父级后面添加内容
                         // tr_obj.after(html);
                      obj.parent().parent().after(html);
                    }
                  })
	            }else{
	                $(this).text('+');
                var pid = tr_obj.attr('pid');

		         // console.log('tr[pid='+pid+']');

		         tr_obj.nextUntil('tr[pid='+pid+']').remove();
            }


         }
        )
        })


		</script>

